from flask import Flask, session
from flask_session import RedisSessionInterface, Session


app = Flask(__name__)
app.secret_key = 'sdfoha'

# 默认
# from flask.sessions import SecureCookieSessionInterface
# app.session_interface = SecureCookieSessionInterface()

# 方式一：redis保存session
# from redis import Redis
# app.session_interface = RedisSessionInterface(
#     redis=Redis(host='127.0.0.1', port=6379),
#     key_prefix='flaskxxx'
# )

# 方式二：redis保存session
# from redis import Redis
# app.config['SESSION_TYPE'] = 'redis'
# app.config['SESSION_REDIS'] = Redis(
#     host='localhost', port=6379
# )
# Session(app)


@app.route('/login')
def login():
    session['k1'] = 123
    return 'login'


@app.route('/index2')
def index2():
    v = session['k1']
    print(v)
    return 'index'


if __name__ == '__main__':
    app.run()

